<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>props类型限制的简写</title>
</head>
<body>
<div id="container">

</div>
</body>
</html>


<!--引入react核心库-->
<script type="text/javascript" src="../Js/react.development.js"></script>
<!--引入react-dom库,用于支持react操作dom-->
<script type="text/javascript" src="../Js/react-dom.development.js"></script>
<!--引入babel库,用于将jsx转成js-->
<script type="text/javascript" src="../Js/babel.min.js"></script>
<!--引入prop-types库,用于将对props进行类型限制-->
<script type="text/javascript" src="../Js/prop-types.js"></script>


<script type="text/babel">//此处一定要写text/babel，将jsx转成js
class Form extends React.Component{

    //props类型限制（用static修饰，将其挂载到类本身，不加是挂载到类的实例上）
    static propTypes={
        name:PropTypes.string.isRequired,
        age:PropTypes.number.isRequired,
        sex:PropTypes.string.isRequired,
    }

    // props默认值（用static修饰，将其挂载到类本身，不加是挂载到类的实例上）
    static  defaultProps={
        name:'zs',
        age:18,
        sex:'男',
    }


    render(){
        const {name,age,sex}=this.props
        return <div>
            <ul>
                <li>{name}</li>
                <li>{age}</li>
                <li>{sex}</li>
            </ul>
        </div>
    }
}

const Person={
    name:"张三",
    age:18,
    sex:"男"
}

ReactDOM.render(<Form {...Person}/>,document.getElementById("container"))

</script>

